<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Layui(v2.5.4) 文件上传</title>
	<link rel="stylesheet" href="../js/layui_v2.5.4/css/layui.css">
	<script type="text/javascript" src="../js/layui_v2.5.4/layui.all.js"></script>
	<style>
		body{margin: 20px 50px;}
	</style>
</head>
<body>
	<p>Layui v2.x 文件上传</p><hr>
	<button type="button" class="layui-btn" id="test">
	  	<i class="layui-icon">&#xe67c;</i>上传图片
	</button>
	<script>
		layui.use('upload', function(){
		  	var upload = layui.upload;
		  	//执行实例
		  	upload.render({
		    	elem: '#test' //绑定元素
		    	,url: 'php/upload_two.php' //上传接口
		    	,accept:'images'
		    	,field:'img'
		    	,done: function(res){
		      		//上传完毕回调
		      		if(res.code == 1){
		      			layer.msg(res.msg,{icon:6});
		      			console.log(res.data);
		      		}
		    	}
		    	,error: function(){
		      		//请求异常回调
		      		layer.msg('网络错误',{icon:5});
		    	}
		  	});
		}); 
	</script>
</body>
</html>